<?php

namespace App\Http\Middleware;

use App\Models\AppUsers;
use Closure;

class CheckToken
{
    /**
     * Handle an incoming request.
     *
     * @param \Illuminate\Http\Request $request
     * @param \Closure $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $token = $request->post('token', '');
        $uuid  = $request->post('uuid', '');
        $user  = AppUsers::where('api_token', $token)->where('uuid', $uuid)->first();
        if ($token == null || $user == null) {
            return response()->json([
                'code'     => -1,
                'messages' => '缺少token,请重新登陆',
                'data'     => []
            ]);
        }
        return $next($request);
    }
}
